package com.itheima.controller;

import com.itheima.R;
import com.itheima.pojo.db.PmsSkuStock;
import com.itheima.service.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chensen
 * @create 2022/10/14/20:19
 */
@RestController
@RequestMapping("sku")
public class PmsSkuStockController {
    @Autowired
    private PmsSkuStockService pmsSkuStockService;
    /**
     * 批量更新sku库存信息
     * @param pid
     * @param skuStockList
     * @return
     */
    @PostMapping("update/{pid}")
    public R update(@PathVariable Long pid, @RequestBody List<PmsSkuStock> skuStockList){
        return pmsSkuStockService.update(pid,skuStockList);
    }

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param pid
     * @param keyword
     * @return
     */
    @GetMapping("{pid}")
    public R list(@PathVariable Long pid, @RequestParam(value = "keyword",required = false) String keyword){
        return pmsSkuStockService.selectList(pid,keyword);
    }
}
